package com.lry.basic.algorithm.common;

import java.util.*;

/**
 * 5
 * 8 6
 * 10 8
 * 6 0
 * 20 8
 * 2 6
 * 8
 *
 * 剩余目录2，6
 */
public class DelDir {

    //只记录一级孩子
    static  Map<Integer, List<Integer>> child = new HashMap<>();
    static int [][] dirs = new int[][]{{8,6},{10,8},{6,0},{20,8},{2,6}};
    static int del = 8;
    static Set<Integer> all = new TreeSet<>();

    public static void main(String[] args) {

        for(int i=0;i<dirs.length;i++){
            all.add(dirs[i][0]);
            all.add(dirs[i][1]);
            int finalI = i;
            child.compute(dirs[i][1],(k, v)->{
                if(null==v){
                    v = new ArrayList<>();
                }
                v.add(dirs[finalI][0]);
                return v;
            });
        }
        all.remove(0);
        all.remove(8);

        remove(del);

        System.out.println(all);
    }

    private static void remove(int del){
        List<Integer> list = child.get(del);
        if(null==list||list.isEmpty()){
            return;
        }

        all.removeAll(list);
        for (Integer integer : list) {
            remove(integer);
        }
    }



}
